<?php
/**
 * User: hjd-yao
 * Date: 2019/6/13
 * Time: 16:43
 */

namespace Shop\Http\Requests;


use Illuminate\Foundation\Http\FormRequest;

class UpdatePwdRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        if(!$this->isMethod('post')){
            return [];
        }
        $action = 'login';
        if(request()->route()->hasParameter('action')){
            $action = request()->route()->parameter('action');
        }
        if ($action == 'login'){
            return [
                'old_pwd'=>'required',
                'new_pwd'=>'required|between:6,24',
                're_new_pwd'=>'required|same:new_pwd',
            ];
        }else{
            return [
                'old_pay_pwd'=>'required',
                'pay_pwd'=>'required|between:6,24',
                're_pay_pwd'=>'required|same:pay_pwd',
            ];
        }
    }


    public function messages()
    {
        return [
            'required'=>':attribute不能为空',
            'between'=>':attribute长度必须在:min到:max之间',
            'same'=>':attribute必须和:field相同',
        ];
    }

    public function attributes()
    {
        return [
            'new_pwd'=>'新登录密码',
            're_new_pwd'=>'确认登录密码',
            'pay_pwd'=>'新支付码',
            're_pay_pwd'=>'确认支付密码',
            'old_pay_pwd'=>'原安全密码',
            'old_pwd'=>'原登录密码',
            'my_safe_pwd'=>'安全密码',
        ];
    }
}